﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TheHeInfo.Util;
using TheHeInfoDao;

namespace TheHeInfo.Master
{
    public partial class UcUserLogin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            if(!ASPxCaptcha1.IsValid) return;
            string user = txtUserName.Text;
            string pwd = PwdEncryption(txtPassword.Text);
            var data = TheheInfoDaoHelper.QueryDb(ent => ent.Users.FirstOrDefault(p => p.UserName == user && p.Password == pwd)) as User;
            if (data == null)
            {
                InvalidLoginPopup.ShowOnPageLoad = true;
            }
            else
            {
                Session[SessionNames.USER_DATA] = new UserSessionData(){UserTable = data};
                switch (data.UserTypeCode)
                {
                    case 99://Sa
                        break;
                    case 90: //admin
                        break;
                    case 1://user
                        Response.Redirect("~/Home/Home.aspx");
                        break;
                    default:
                        break;
                }
            }
        }

        protected string PwdEncryption(string pwd)
        {
            return pwd;
        }

    }
}